PREFIX=/usr/local
SOURCES=$(shell echo *.c)
OBJECTS=$(SOURCES:.c=.o)
TARGETS=sheeva-nandrs-decode sheeva-ubootenv-decode
ALIASES=sheeva-nandrs-encode sheeva-ubootenv-encode 
SCRIPTS=sheeva-ubootenv-print sheeva-ubootenv-save
HGVERSION=$(shell hg id)
CFLAGS=-Wall -fno-strict-aliasing -O -g -DHGVERSION="\"${HGVERSION}\""
CC=gcc

all: $(TARGETS) $(ALIASES)

sheeva-nandrs-decode: sheeva-nandrs-decode.o ecc_rs.o do_write.o

sheeva-nandrs-encode: sheeva-nandrs-decode
	ln -f $< $@

sheeva-ubootenv-decode: sheeva-ubootenv-decode.o crc32.o do_write.o

sheeva-ubootenv-encode: sheeva-ubootenv-decode
	ln -f $< $@

clean:
	rm -f $(TARGETS) $(OBJECTS) .depend *~

install: all
	install -s -o root -g root $(TARGETS) -t $(PREFIX)/sbin
	install -o root -g root $(SCRIPTS) -t $(PREFIX)/sbin
	cd $(PREFIX)/sbin ; \
	ln -f sheeva-ubootenv-decode sheeva-ubootenv-encode ; \
	ln -f sheeva-nandrs-decode sheeva-nandrs-encode

.depend: *.[ch]
	$(CC) -MM $(SOURCES) >.depend

-include .depend

.PHONY: clean all install

